package com.thomas.framework.service.impl;

import com.thomas.framework.core.AppException;
import com.thomas.framework.core.ServiceBase;
import com.thomas.framework.dao.ISysDictionaryGroupDao;
import com.thomas.framework.entity.SysDictionary;
import com.thomas.framework.entity.SysDictionaryGroup;
import com.thomas.framework.service.ISysDictionaryGroupService;
import com.thomas.framework.service.ISysDictionaryService;
import com.thomas.framework.utils.CommonUtil;
import com.thomas.framework.utils.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by taohj on 2014/4/17.
 */

@Service
public class SysDictionaryGroupServiceImpl extends ServiceBase<SysDictionaryGroup> implements ISysDictionaryGroupService {


    @Autowired
    private ISysDictionaryGroupDao dao;


    private ISysDictionaryService dictionaryService;


    @Autowired
    public void setDictionaryService(ISysDictionaryService dictionaryService) {
        this.dictionaryService = dictionaryService;
    }

    @Override
    public  boolean create(SysDictionaryGroup group){
        group.setId(CommonUtil.getUUID());
        return  dao.insert(group)>0;
    }

    @Override
    public  boolean remove(SysDictionaryGroup group){
        List<SysDictionary> list=dictionaryService.getListByDictionaryGroup(group);
        if (list!=null && list.size()>0){
            throw  new AppException("please Remove child first .");
        }
        return  dao.delete(group)>0;
    }

    @Override
    public boolean modify(SysDictionaryGroup group){
        return  dao.update(group)>0;
    }


    @Override
    public  SysDictionaryGroup   getById(SysDictionaryGroup group){

        return  dao.selectById(group);
    }

    @Override
    public List<SysDictionaryGroup> getList(SysDictionaryGroup group) {
        return dao.selectList(group);
    }


    @Override
    public PageResult<SysDictionaryGroup> getByPage(PageResult<SysDictionaryGroup> pageResult){
        return  pageResult.setRows(dao.selectbyPage(pageResult));
    }

    @Override
    public SysDictionaryGroup get(SysDictionaryGroup group) {
        return dao.select(group);
    }

}
